#pragma once
#include "QueryCreator.h"

QueryCreator* QueryCreator::queryCreator = NULL;

QueryCreator::QueryCreator() {
	currentQuery = NULL;
}

QueryCreator *QueryCreator::getQueryCreator() {
	if(queryCreator == NULL) {
		queryCreator = new QueryCreator();
	} 

	return queryCreator;
}


void QueryCreator::createNewQuery() {
	currentQuery = new CompleteQuery();
}

void QueryCreator::addSynonym(Synonym *syn) {
	currentQuery->addDeclarationParameters(syn);
}

void QueryCreator::addResult(Result *result) {
	currentQuery->setResult(result);
}

void QueryCreator::addQuery(QueryType queryType, Synonym *arg1, Synonym *arg2) {
	Query *newQuery;
	switch(queryType) {
		case MODIFIES:
			newQuery = new QueryModifies(arg1, arg2);
			break;
		case USES:
			newQuery = new QueryUses(arg1, arg2);
			break;
		case FOLLOWS:
			newQuery = new QueryFollows(arg1, arg2);
			break;
		case FOLLOWSSTAR:
			newQuery = new QueryFollowsStar(arg1, arg2);
			break;
		case PARENT:
			newQuery = new QueryParent(arg1, arg2);
			break;
		case PARENTSTAR:
			newQuery = new QueryParentStar(arg1, arg2);
			break;
		default:
			//Throw some exception
			break;	
	}

	currentQuery->addSuchThatQuery(newQuery);
}

void QueryCreator::addQuery(QueryType queryType, Synonym *arg1, Synonym *arg2, Synonym *arg3) {
	Query *newQuery = new QueryPattern(arg1, arg2, arg3);
	currentQuery->addPatternQuery(newQuery);
}

CompleteQuery* QueryCreator::getCompleteQuery() {
	return currentQuery;
}

QueryCreator::~QueryCreator() {
	
}